<?php include '../nav.php'; ?>
<?php 
	//接收商品
	$gid = $_GET['id'];
		// var_dump($gid);  
	
	// var_dump($gid); exit;
	$sql = 'select i.icon, g.name, g.desc, g.price, g.sales, g.id, g.stock
			from goods g, goodsImg i
			where g.id = i.gid and up = 1 and face = 1 and g.id='.$gid;
	$goods_list = query($sql)[0];
			// var_dump($goods_list);  

	//查询商品所有的图片
	$sql ='select icon from goodsImg where gid='.$gid;
	// var_dump($sql); 


	$img_list = query($sql);
	// var_dump($img_list); exit;
 ?>
<link rel="stylesheet" href="<?= CSS?>goods.css">
<link rel="stylesheet" href="<?= PUB_CSS?>commond.css">
	<div class='goods clear'>
		<div class='hr-20'></div>
		<div class='hr-10'></div>
	

		<div class='goods-page clear'>
		<a href="<?= URL?>home/index.php">首页 </a>
		<span>&nbsp;&nbsp;&gt;&nbsp;&nbsp;<?= $goods_list['name']?>	</span>>	
		<div class='goods-case clear'>
			<div class='goods-leftarea clear'>
				<div class='imgs'>
					<div class='big'>
						<img src="<?= img_url($goods_list['icon'],360)?>" width='360px'>
						
					</div>
					<ul class='small'>
					
					<?php foreach($img_list as  $v): ?>
					
						<li><a href=""><img src="<?= img_url($v['icon'])?>" class='active' width='50px'></a></li>		
					<?php endforeach; ?>	
					</ul>
				</div>
			</div>

			<div class='goods-rightarea'>
				<div class='goods-content'>
					<h3 class='goods_name'><?= $goods_list['name']?></h3>
					<h4 class='goods_desc'><?= $goods_list['desc']?></h4>
				<div class='hr-5'></div>
					<div class='dl'></div>
						<div class='dt'>华为价:￥<?= $goods_list['price']?><b></b></div>
						<div class='dd' class='store'>&nbsp;( 库存 <?= $goods_list['stock']?> 件 )</div>
						<div class='dd' class='yishou'>已售 <?= $goods_list['sales']?> 件</div>
						<div class='dd'>运费: 满 99 免运费</div>
						<div class='dd'>商品评分:  （共 70472 条评论）</div>
					<div class='hr-5'></div>
						<div class='select'>
						<div class='hr-10'></div>

							
						<div class='dl-color clear'>
							<div class='dt'>选择颜色:
							<div class='dd clear'>
								<div class='color'>
								<img src="/lamp_shop/public/home/images/40_40_yd-bai.jpg" alt="">白色</div>
								<div class='color2'><img src="/lamp_shop/public/home/images/40_40_yd-hei.jpg" alt="">黑色
								</div>

								</div>
							</div>	
						</div>
					<form action="action.php" method='get'>
					<div class='dl'>
						<div class='dt'>购买数量:</div>
						<div class='dd goods-dd clear'>
							<div class='subtraction'><strong href="" id="count_add" title='减少数量' value='jian' onclick="jian()">-</strong></div>
							<div class='number'>
								<div class='input'><input type="text" name='count' id='mynum'value='1'></div>
							</div>
							<div class='plus'><strong href="" id="count_sub"  title='增加数量' value='jia' onclick="jia()">+</strong></div>
								
						</div>
					<div class='opt'>已选择
						<span><?= $goods_list['name']?></span>
					</div>
						<div class='goods-botton'><input class='botton' type="submit" value='加入购物车'>
					</div>		
					</div>
					<div class="sub-order">
						<input type="hidden" name="bz" value="cart">
						<input type="hidden" name="gid" value="<?=$goods_list['id']?>">
						<input type="hidden" name="stock" value="<?=$goods_list['stock']?>">
						<!-- <input type='submit' value='加入购物车' class='add_cart'>
					</div>
				</form>
					
					
				</div>				
			</div>
		</div>			
	</div>
<!-- 		<div class='goods-layout clear'>
			<div class='left'></div>
			<div class='right'></div>
		</div>
	</div>	 -->




<script>
	// 通过id 获取 购买数量表单 的对象
	var mynum = document.getElementById('mynum');   

	function jian(){
		// mynum.value  是代表 id为mynum的value值
		// 正常减1
		if(  mynum.value  > 0 ){
			mynum.value = mynum.value - 1;
		}

		// 判断如果购买数量小于1(负值或者0) ,直接赋值1 
		if( mynum.value < 1){
			mynum.value = 1;
		}
	}


	function jia(){
		if(parseInt(mynum.value) > 0){
			mynum.value = parseInt(mynum.value) + 1;
		}
		if(parseInt(mynum.value) < 0){
			mynum.value = 1;
		}
	}
		//  js中 + 是作为拼接符, 

</script>